﻿<?php

// install.php
$hostname = $_POST['hostname'];
$username = $_POST['user'];
$password = $_POST['password'];
$dbname   = $_POST['dbname'];


$MANV = $_POST['MNV'];
$HoTen = $_POST['HoTen'];
$password1 = $_POST['password1'];

$username = addslashes($username);
$password1 = addslashes($password1);

if($hostname && $username && $dbname)
{
    $content ='<?';
    $content.= 'DEFINE ("DB_USER","'.$username.'");';
	$content.= 'DEFINE ("DB_PASSWORD","'.$password.'");';
	$content.= 'DEFINE ("DB_HOST","'.$hostname.'");';
	$content.= 'DEFINE ("DB_NAME","'.$dbname.'");';
	
	$content.= '$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);';
	
	$content.= 'mysql_select_db (DB_NAME);';
    
    
    $file = fopen('../config.php','w');
    fwrite($file,$content,1000);
    
    fclose($file);
    
    //include ('../config.php');
    //$fp = fopen('db.sql',"r");
    //$db = fread($fp,50000);
    //fclose($fp);


    $sql = explode(";",file_get_contents('db.sql'));// 
    
    foreach($sql as $query)
    
    mysql_query($query);
    
    
    //passthru("nohup mysql -u root -p  DBNAME < db.sql");
    
    require('../config.php');
    $query = "INSERT INTO nhanvien VALUES ('$MANV','$HoTen','admin', MD5('$password1'))";
    @mysql_query($query);
    
    echo '<center><p><font size="30"><strong>CÀI ĐẶT THÀNH CÔNG</strong></font></p></center>';
    echo '<p align = "center"> Sau khi cài đặt thành công xin xóa thư mục install trên ổ đĩa</p>';
    echo '<!--';

}
?>

<center><p><font size="30"><strong>CÀI ĐẶT</strong></font></p></center>
<br /><br /><br /><br />

<form method="post">
<center>

<table>

<tr>
    <td colspan="2" align="center">THIẾT ĐẶT CẤU HÌNH MYSQL SERVER <br /> </td> 
</tr>

<tr>
    <td>host</td>
    <td align="right"> <input type="text"  name="hostname" value="localhost"/></td>
</tr>

<tr>
    <td>username</td>
    <td align="right"> <input type="text" name="user" value="root" /></td>
</tr>

<tr>
    <td>password</td>
    <td align="right"> <input type="password" name="password" value=""/></td>
</tr>



<tr>
    <td>Database name</td>
    <td align="right"> <input type="text" name="dbname" value="QLCB" /></td>
</tr>

<tr>
<td colspan="2"> <font color="red"><p align="center"> THÔNG TIN QUẢN TRỊ VIÊN </p></font></td>

</tr>
<tr>
    <td>tên đăng nhập</td>
    <td align="center"> admin <input  type="hidden" name="MNV" value="admin"/></td>
    
    
</tr>

<tr>
    <td>password</td>
    <td align="right"> <input type="password" value="" name="password1" /> </td>
</tr>

<tr>
    <td>Họ Tên</td>
    <td align="right"><input type="text" name="HoTen" /></td>

</tr>



<tr>
    <td colspan="2" align="center"> <input type="submit" name="submit" value="CÀI ĐẶT" /></td>
</tr>
</table>
</form>
</center>
